package com.enjoybyte.pangu.util;

import com.enjoybyte.pangu.enums.ResultCode;
import lombok.Data;

@Data
public final class Result {

    private Integer code;

    private String msg;

    private Object data;

    private Long timestamp;

    private Result(){}

    /**
     * 操作成功
     * @return Result
     */
    public static Result ok() {
        Result result = new Result();
        result.setCode(ResultCode.OK.getCode());
        result.setMsg(ResultCode.OK.getMsg());
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    /**
     * 操作成功带返回值
     * @param data
     * @return Result
     * @param 
     */
    public static Result ok(Object data) {
        Result result = Result.ok();
        result.setData(data);
        return result;
    }

    /**
     * 自定义返回信息
     * @param code
     * @param msg
     * @return Result
     */
    public static Result fail(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    /**
     * 自定义返回信息
     * @param code
     * @param msg
     * @param data
     * @return Result
     */
    public static Result fail(Integer code, String msg, Object data) {
        Result result = Result.fail(code,msg);
        result.setData(data);
        return result;
    }

}
